package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @Author:郭
 * @Description: TODO
 * @Date: 2022/11/13 16:06
 * @ClassName PeiZhi
 * 跨域的配置类
 */
@Configuration
public class PeiZhi {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        //是否发送cookie
                        .allowCredentials(false)
                        //放行哪些域
                        .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                        .allowedOrigins("*")
                        .allowedHeaders("*")
                        .exposedHeaders("*");
            }
        };
    }
}
